package com.happyfamily.springboot.crowdsourcingplatform.service.weng.impl;

import com.happyfamily.springboot.crowdsourcingplatform.base.result.Results;
import com.happyfamily.springboot.crowdsourcingplatform.dao.weng.NeedDao;
import com.happyfamily.springboot.crowdsourcingplatform.model.Need;
import com.happyfamily.springboot.crowdsourcingplatform.service.weng.BackNeedService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
@Slf4j
public class BackNeedServiceImpl implements BackNeedService
{
	@Autowired
	NeedDao needDao;

	@Override
	public Results<Need> getAllNeedsByPage(Integer startPosition, Integer limit)
	{
		return Results.success(needDao.countAllNeeds().intValue(), needDao.getAllNeedsByPage(startPosition, limit));
	}

	@Override
	public int deleteNeed(Long nid)
	{
		return needDao.deleteNeed(nid);
	}

	@Override
	public Need getNeedById(Long nid)
	{
		return needDao.getById(nid);
	}

	@Override
	public Results passVerify(Need need)
	{
		if (need != null)
		{
			needDao.passVerifyByNeedId(need.getNid());
			return Results.success();
		} else
		{
			return Results.failure();
		}
	}

	@Override
	public Results unPassVerify(Need need)
	{
		if (need != null)
		{
			needDao.unPassVerifyByNeedId(need.getNid());
			return Results.success();
		} else
		{
			return Results.failure();
		}
	}

	@Override
	public Results<Need> getNeedByFuzzyNeedTitle(String ntitle, String verifyState, String tenderState, String startTime, String endTime, Integer startPosition, Integer limit)
	{
		return Results.success(needDao.getNeedByFuzzyNeedTitle(ntitle,verifyState, tenderState, startTime, endTime).intValue(), needDao.getNeedByFuzzyNeedNamePage(ntitle, verifyState, tenderState, startTime, endTime, startPosition, limit));
	}


}
